package com.example.administrator.fragarmentdemotest_a.fragarment_demo.dao;


import com.example.administrator.fragarmentdemotest_a.fragarment_demo.Bean.FeatureBean;

import java.util.List;

import io.realm.Realm;
import io.realm.RealmResults;

public class FeatureDao {

    public List<FeatureBean> findAllShow() {
        Realm realm = Realm.getDefaultInstance();
        RealmResults<FeatureBean> all = realm.where(FeatureBean.class).equalTo("showType", "1").findAll();
        List<FeatureBean> beans = realm.copyFromRealm(all);
        realm.close();
        return beans;
    }
    public List<FeatureBean> findAllOpen() {
        Realm realm = Realm.getDefaultInstance();
        RealmResults<FeatureBean> all = realm.where(FeatureBean.class).equalTo("showType", "1").findAll();
        List<FeatureBean> beans = realm.copyFromRealm(all);
        realm.close();
        return beans;
    }

    public List<FeatureBean> findAllClose() {
        Realm realm = Realm.getDefaultInstance();
        RealmResults<FeatureBean> all = realm.where(FeatureBean.class).equalTo("showType", "0").findAll();
        List<FeatureBean> beans = realm.copyFromRealm(all);
        realm.close();
        return beans;
    }
    public void update(FeatureBean bean) {
        Realm realm = Realm.getDefaultInstance();
        realm.beginTransaction();
        realm.insertOrUpdate(bean);
        realm.commitTransaction();
        realm.close();
    }

}
